newsletter.admin = liwe.module ( 'newsletter.admin', null, "Newsletter" );

newsletter.admin._dest_div = "system-content";
newsletter.admin._visiblecnt = {};
newsletter.admin._sent_data = null;
newsletter.admin._select_opts = {};
//{{{newsletter.admin._init = function ( dest_div )
newsletter.admin._init = function ( dest_div )
{
    if ( dest_div ) newsletter.admin._dest_div =  dest_div;
    var _acts = [
	    		    { label: 'Iscritti', func: function () { newsletter.admin._load_section( 'subscriber' );} },
	    		    { label: 'Gruppi', func: function () { newsletter.admin._load_section( 'group' );} },
					{ label: 'Modelli', func: function () { newsletter.admin._load_section( 'info' );} },
        			{ label: 'Invio', func: function () { newsletter.admin._load_section( 'sent' );} }
        		//	{ label: 'Relazioni', func: function () { newsletter.admin._load_section( 'relation' );} }
    			];
    
    newsletter.admin.register ( _acts );
    newsletter.admin._am_subscriber_init ( 'subscriber_list' );
	newsletter.admin._am_info_init ( 'info_list' );
	newsletter.admin._am_sent_init ( 'sent_list' );
	newsletter.admin._am_group_init ( 'group_list' );
	newsletter.admin._cache_group_opts ();
};
//}}}
//{{{newsletter.admin._load_section = function ( section )
newsletter.admin._load_section = function ( section )
{
	
    newsletter.admin._visiblecnt = { subscriber : '', info : '', group : '', sent : '', relation : '' };
    var _func = newsletter.admin [ "_render_" + section ];
    _func ();
};  
//}}} 
//{{{newsletter.admin._cache_group_opts = function ( cback )
newsletter.admin._cache_group_opts = function ( cback )
{
	var post = { 'action' : 'newsletter.ajax.list_group' };
    newsletter.ajax ( post , function ( resp )
	{
        var g_opts = [];
        resp.group.iterate ( function ( data )
        {   
            g_opts.push ( { label : data [ 'title' ], value : data  [ 'id_group' ] } );
        } );
		newsletter.admin._select_opts [ 'group' ] = g_opts;
		if ( cback ) cback();
	} );
};
//}}}
//{{{newsletter.admin._show_cnt = function ( cnt_to_show, section )
newsletter.admin._show_cnt = function ( cnt_to_show, section )
{
    var _el;
    if ( newsletter.admin._visiblecnt [ section ] != '' )
    { 
        liwe.fx.fade_out ( newsletter.admin._visiblecnt [ section ] );
        _el = $el ( newsletter.admin._visiblecnt [ section ] );
        _el.style.display = "none";
    };
    _el = $el ( cnt_to_show );
    _el.style.display = "block";
    liwe.fx.fade_in ( cnt_to_show );
    newsletter.admin._visiblecnt [ section ] = cnt_to_show;
};
//}}}
//{{{newsletter.admin._show_message = function ( title, msg, cback )
newsletter.admin._show_message = function ( title, msg, cback_confirm, cback_cancel, size, no_button )
{
		if ( typeof ( size ) == 'undefined' ) var size =  [ 350, 5 ];
		liwe.lightbox.create ( 'nl_message', size[ 0 ], size [ 1 ] );
		//contenuto
		var _box = $el ( 'nl_message' );
		var _title = document.createElement ( 'h4');
		_title.className = "seph_e";
		_title.innerHTML = title;
		_box.appendChild ( _title );
		var _message = document.createElement ( 'div');
		_message.className = "seph_b";
		_message.innerHTML = msg
		_box.appendChild ( _message );
	
		if ( no_button != true )
		{
		    var _btn_cancel= document.createElement ( 'div' );
		    _btn_cancel.id = "message_btn_cancel";
		    _btn_cancel.className = "button blue";
		    _btn_cancel.innerHTML = "Annulla";
		    liwe.events.add ( _btn_cancel , 'click', function ()
		    {
			    if ( cback_cancel ) cback_cancel();
			    liwe.lightbox.close()
		    });
		    _box.appendChild ( _btn_cancel );
	    
		    var _btn_confirm = document.createElement ( 'div' )
		    _btn_confirm.id = "message_btn_elimina";
		    _btn_confirm.className = "button grey";
		    _btn_confirm.innerHTML = "Conferma";
		    liwe.events.add ( _btn_confirm , 'click', function () 
		    { 
			    if ( cback_confirm ) cback_confirm();
			    liwe.lightbox.close()
		    } );
		    _box.appendChild ( _btn_confirm );
		} else {
		    var _btn_cancel= document.createElement ( 'div' );
		    _btn_cancel.id = "message_btn_cancel";
		    _btn_cancel.className = "button blue";
		    _btn_cancel.innerHTML = "OK";
		    liwe.events.add ( _btn_cancel , 'click', function ()
		    {
			    liwe.lightbox.close()
		    });
		    _box.appendChild ( _btn_cancel );
		};
		liwe.fx.set_opacity ( _box , 0 );
		liwe.lightbox.show ();
		liwe.fx.fade_in ( _box, null, 2000 );

};
//}}}
//{{{SUBSCRIBER
//{{{newsletter.admin._render_subscriber =  function()
newsletter.admin._render_subscriber =  function()
{
	var _dct, _admin_title;
	var _admin_title = String.formatDict ( newsletter.templates [ 'ADMIN_TITLE' ], { '_title' : 'GESTIONE ISCRITTI' } ); 

	_dct = { '_admin_title' : _admin_title, '_list_title' : 'Elenco Iscritti' , '_form_title' : 'Inserimento/modifica iscritti'  };

	$(newsletter.admin._dest_div, String.formatDict ( newsletter.templates [ 'ADMIN_SUBSCRIBER_LAYOUT' ], _dct ) );
	newsletter.admin._subscriber_refresh ();

};
//}}}
//{{{newsletter.admin._am_subscriber_init = function ( dest_div )
newsletter.admin._am_subscriber_init = function ( dest_div )
{
        if ( newsletter.admin.am_subscriber ) return;
        newsletter.admin.am_subscriber = new AdminManager
                                ( {
                                        'dest_res': dest_div,
                                        'name' : 'am_subscriber',
                                        'list_action': "newsletter.ajax.list_subscriber",
					'del_action' : "newsletter.admin.del_subscriber",
                                        'mod_menu_actions': [
                                                                 { func: "newsletter.admin._subscriber_form();", 'class' : 'add' , label: 'Aggiungi' },
																 { func : "newsletter.admin._subscriber_import()", 'class' : 'csv_16', label : 'Importa Utenti'}
										                    ],
										'filter_form' : newsletter.admin._subscriber_filter_form,
										'filter_form_name' : "am_subscriber_filter"
                                } );

        newsletter.admin.am_subscriber.set_row_fields (
                                [
                                        [ "ID", "id_subscriber" ],
										[ "Stato Blocco", "_active" ],
										[ "Gruppo", "gr_title" ],
										[ "Tipo Utente" , "_user" ],
                                        [ "Data Inserimento", "_created" ],
										[ "e-mail", "email" ],
										[ "Nome", "name" ],
										[ "Cognome", "lastname" ],
										[ "Localit&agrave;", "localita" ],
										[ "Provincia", "provincia" ],
										[ "Nazione", "nazione" ],
										[ "Azienda", "azienda" ],
										[ "Area", "area" ]
                                ]
                                );

        newsletter.admin.am_subscriber.cbacks [ 'row_manip' ] = newsletter.admin._rwman_subscriber;
        newsletter.admin.am_subscriber.cbacks [ 'del_item' ]  = function ( id ) { newsletter.admin.del_subscriber ( id ); };
        newsletter.admin.am_subscriber.cbacks [ 'edit_item' ]  = function ( id ) { newsletter.admin.edit_subscriber ( id ); };
        newsletter.admin.am_subscriber.cbacks [ 'noresult' ] = function () { newsletter.admin._subscriber_form(); };
        newsletter.admin.am_subscriber.cbacks [ 'show_results' ] = function () { newsletter.admin._show_cnt ( 'subscriber_panel_list', 'subscriber' ); };
};
//}}}
//{{{newsletter.admin._am_abbonato_filter_form = function ( dest_div )
newsletter.admin._subscriber_filter_form = function ( dest_div )
{
	var g_opts =  newsletter.admin._select_opts [ 'group' ] ;
	var f = new liwe.form.instance ( 'am_subscriber_filter' );
	f.text ( { 'label' : 'Nome', 'name' : 'name', size : 30, 'maxlength' : 30 , nonl : true } );
	f.text ( { 'label' : 'Cognome', 'name' : 'lastname', size : 30, 'maxlength' : 30, nonl : true } );
	f.email ( { 'label' : 'e-mail', 'name' : 'email' , validator : true, 'mandatory' : true } );
	f.text ( { 'label' : 'Azienda', 'name' : 'azienda', size : 30, 'maxlength' : 30 , nonl : true } );
	f.select ( { 'label' : 'Gruppo', 'name' : 'gruppo', 'options' : g_opts , force_select: true });
	f.text ( { 'label' : 'Localit&agrave;', 'name' : 'localita', size : 30, 'maxlength' : 30, nonl : true } );
	f.text ( { 'label' : 'Provincia', 'name' : 'provincia', size : 30, 'maxlength' : 30, nonl : true } );
	f.text ( { 'label' : 'Nazione', 'name' : 'nazione', size : 30, 'maxlength' : 30 } );
	f.button ( { value: "Applica Filtro", "class" : "green", colspan : 3,onclick: "newsletter.admin._subscriber_filter()", nonl: true } );
	f.button ( { value: "Svuota", "class": "yellow", onclick: "abbonamento.admin._subscriber_refresh()" } );
	f.set ( dest_div );
};
//}}}
//{{{newsletter.admin._subscriber_filter = function ()
newsletter.admin._subscriber_filter = function ()
{
	newsletter.admin.am_subscriber.search_start ();
};
//}}}
//{{{newsletter.admin._rwman_subscriber = function ( ds, row )
newsletter.admin._rwman_subscriber = function ( ds, row )
{
	row [ "_id" ] = row [ 'id_subscriber' ];
	row [ "_created" ] = Date.formatted ( "%d %B %Y", row [ 'created' ].split( " ") [ 0 ]); 
	var _bullet =  [ 'bullet_green', 'bullet_red' ] ;
	var _bloccato = row [ 'bloccato' ];
	row [ '_active' ] = String.formatDict ( newsletter.templates [ 'ADMIN_ICO_16'], { '_class' : _bullet [ _bloccato ] } );
	var _user = ( row.get ( 'uid', '' ) ) ? 'user_reg' : 'user_free';
	row [ '_user' ] = String.formatDict ( newsletter.templates [ 'ADMIN_ICO_16' ] , { '_class' : _user } );
	if (row [ 'gr_title' ] == null ) row [ 'gr_title' ] = "Nessun Gruppo";
};
//}}}
//{{{newsletter.admin._subscriber_refresh =  function ( cback )
newsletter.admin._subscriber_refresh =  function ( cback )
{
	newsletter.admin.am_subscriber.show_list ();
	if ( cback ) cback();
	_el = $el ( "subscriber_import_cnt" );
	_el.style.display = "none";
	liwe.fx.fade_out ( "subscriber_import_cnt" );
};
//}}}
//{{{newsletter.admin.edit_subscriber = function ( id )
newsletter.admin.edit_subscriber = function ( id )
{
        var _post = { action : 'newsletter.ajax.get_subscriber', id_subscriber : id };
        newsletter.ajax ( _post , function ( _resp )
        {
	        newsletter.admin._subscriber_form ( _resp.subscriber );
        });
};
//}}}
//{{{newsletter.admin._subscriber_save =  function ()
newsletter.admin._subscriber_save =  function ()
{
    liwe.utils.notifier.show ( 'Salvato correttamente', 'info', 2000);
};
//}}}
//{{{newsletter.admin.del_subscriber = function ( ids )
newsletter.admin.del_subscriber = function ( ids )
{
		var _title = "Cancellazione Iscritto";
		var _message = "<u>Elimando l'abbonato saranno eliminate tutte le relazioni <b>continuare</b></u>";
		newsletter.admin._show_message ( _title, _message, function ()
		{
			var _post = { 'action' : 'newsletter.admin.del_subscriber', 'ids' : ids };
			newsletter.admin.ajax ( _post , function ()
			{
				newsletter.admin._subscriber_refresh ( function () 
				{
					liwe.utils.notifier.show ( 'Iscritto Elimanato correttamente', 'info', 2000)
				});	
			});
		} );
};
//}}}
//{{{newsletter.admin._subscriber_form ( data )
newsletter.admin._subscriber_form =  function ( data )
{

	if ( typeof ( data ) == "undefined" ) var data = {};
	newsletter.admin._cache_group_opts ( function ()
	{
		var g_opts =  newsletter.admin._select_opts [ 'group' ] ;
		var post = { action : 'user.admin.list' };
		user.ajax ( post, function ( resp )
		{
			var user_opts = [];
			resp.users.iterate ( function ( user )
			{
				var _uid = user  [ 'uid' ];
				user_opts.push ( { 'label' : user [ 'login' ], 'value' : _uid } )
			});
		
			var id = data.get ( 'id_subscriber', 0 ) ;
			var dest_div = 'subscriber_form';
			if ( typeof ( data ) == 'undefined' ) data = {};
			var f = new liwe.form.instance ( 'am_subscriber_form' );
			f.events [ 'complete' ] = newsletter.admin._subscriber_save;
			f.hidden ( "action", 'newsletter.ajax.set_subscriber' );
			f.hidden ( 'id_subscriber', id );
			f.email ( { 'label' : 'e-mail', 'name' : 'email' , 'value' : data.get ( 'email', '' ), 'mandatory' : true } );
			f.text ( { 'label' : 'Nome', 'name' : 'name', size : 30, 'maxlength' : 30, 'value' : data.get ( 'name' , '' ) } );
			f.text ( { 'label' : 'Cognome', 'name' : 'lastname', size : 30, 'maxlength' : 30, 'value' : data.get ( 'lastname' , '' ) } );
			//f.select ( { 'label' : 'Utente Collegato', 'name' : 'uid', 'options' : user_opts, onchange : "newsletter.admin._reload_extra()", force_select : true, 'value' : data.get ( 'uid' , 0 )   } );
			f.select ( { 'label' : 'Utente Collegato', 'name' : 'uid', 'options' : user_opts, force_select : true, 'value' : data.get ( 'uid' , 0 )   } );
			f.text ( { 'label' : 'Localit&agrave;', 'name' : 'localita', size : 30, 'maxlength' : 30, 'value' : data.get ( 'localita' , '' ) } );
			f.text ( { 'label' : 'Provincia', 'name' : 'provincia', size : 30, 'maxlength' : 30, 'value' : data.get ( 'provincia' , '' ) } );
			f.text ( { 'label' : 'Nazione', 'name' : 'nazione', size : 30, 'maxlength' : 30, 'value' : data.get ( 'nazione' , '' ) } );
			f.text ( { 'label' : 'Azienda', 'name' : 'azienda', size : 30, 'maxlength' : 30, 'value' : data.get ( 'azienda' , '' ) } );
			f.text ( { 'label' : 'Area', 'name' : 'area', size : 30, 'maxlength' : 30, 'value' : data.get ( 'area' , '' ) } );
			f.checkbox ( { label: 'Bloccato', name: 'bloccato', checked : !!parseInt ( data.get ( 'bloccato', 0 ) ), 'value' : 1 } );
			f.select ( { 'label' : 'Gruppo', 'name' : 'gruppo', 'options' : g_opts , value : data.get ( 'gruppo', 0 ), force_select: true });
			f.jconed ( { 'label' : 'Note', 'name' : "note", width: 300, height: 200, colspan : 5, value : data.get ( 'note' , '' ) } );
			f.submit ( { value: 'Salva', 'class' : "button green",nonl : true, colspan : 2 } );
			f.button ( { value: 'Elenco', 'class' : "grey", onclick : "newsletter.admin._subscriber_refresh()"} );
			f.set ( dest_div );
			newsletter.admin._show_cnt ( 'subscriber_panel_form', 'subscriber' );
			//newsletter.admin._subscriber_extra( id, data.get ( 'uid' , 0 ) );
		} );
	} );
};
//}}}

//{{{newsletter.admin._subscriber_import = function ()
newsletter.admin._subscriber_import = function ()
{
	newsletter.admin._subscriber_import_form();
	_el = $el ( "subscriber_import_cnt" );
	_el.style.display = "block";
	liwe.fx.fade_in ( "subscriber_import_cnt" );
	
}
//}}}
//{{{newsletter.admin._subscriber_import_form = function ()
newsletter.admin._subscriber_import_form = function ()
{
	var g_opts =  newsletter.admin._select_opts [ 'group' ] ;
	var f  = new liwe.form.instance ( "import_form" );
	f.events [ 'complete' ] = function ()  { newsletter.admin._subscriber_refresh() };
	f.events [ 'start' ] = newsletter.admin._subscriber_check_import;
	f.hidden ( 'action', 'newsletter.admin.subscriber_import' );
	f.select ( { label : 'Gruppo esisitente', name : 'id_group', 'options' : g_opts , force_select: true });
	f.text ( { label : 'Nuovo Gruppo', name : 'new_group' } );
	f.upload ( { name : "csv", label : "Selziona file" , mandatory : true } );
	f.submit ( { value: 'Importa', 'class': 'button green' } );
	f.set ( "subcriber_import_form" );
};
//}}}
//{{{newsletter.admin._subscriber_check_import = function ()
newsletter.admin._subscriber_check_import = function ()
{
	var f = liwe.form.get ( "import_form" );
	var group = f.get_value ( "id_group" );
	var new_group = f.get_value ( "new_group" );
	if ( !group && !new_group  )
	{
		alert ( "inserire o selezionare un gruppo" );
		return false;
	};
	return true;
};
//}}}
//}}}
//{{{INFO
//{{{newsletter.admin._render_info =  function()
newsletter.admin._render_info =  function()
{
	var _dct, _admin_title;
	var _admin_title = String.formatDict ( newsletter.templates [ 'ADMIN_TITLE' ], { '_title' : 'GESTIONE MODELLI' } ); 

	_dct = { '_admin_title' : _admin_title, '_list_title' : 'Elenco modelli' , '_form_title' : 'Inserimento/modifica modelli'  };

	$(newsletter.admin._dest_div, String.formatDict ( newsletter.templates [ 'ADMIN_INFO_LAYOUT' ], _dct ) );
	newsletter.admin._info_refresh ();

};
//}}}
//{{{newsletter.admin._am_info_init = function ( dest_div )
newsletter.admin._am_info_init = function ( dest_div )
{
        if ( newsletter.admin.am_info ) return;
        newsletter.admin.am_info = new AdminManager
                                ( {
                                        'dest_res': dest_div,
                                        'name' : 'am_info',
                                        'list_action': "newsletter.ajax.list_info",
                                        'mod_menu_actions': [
                                                                 { func: "newsletter.admin._info_form();", 'class' : 'add' , label: 'Aggiungi' }
                    ]
                                } );

        newsletter.admin.am_info.set_row_fields (
                                [
                                        [ "ID", "id_info" ],
                                        [ "Mittente", "sender" ],
					[ "Titolo" , "title" ],
					[ "Oggetto", "subject" ],
					[ "Ora di invio", "_send_time" ],
                                        [ "Data creazione", "_created" ]
                                ]
                                );

        newsletter.admin.am_info.cbacks [ 'row_manip' ] = newsletter.admin._rwman_info;
        newsletter.admin.am_info.cbacks [ 'del_item' ]  = function ( id ) { newsletter.admin.del_info ( id ); };
        newsletter.admin.am_info.cbacks [ 'edit_item' ]  = function ( id ) { newsletter.admin.edit_info ( id ); };
        newsletter.admin.am_info.cbacks [ 'noresult' ] = function () { newsletter.admin._info_form(); };
        newsletter.admin.am_info.cbacks [ 'show_results' ] = function () { newsletter.admin._show_cnt ( 'info_panel_list', 'info' ); };
};
//}}}
//{{{newsletter.admin._rwman_info = function ( ds, row )
newsletter.admin._rwman_info = function ( ds, row )
{
	row [ "_id" ] = row [ 'id_info' ];
	row [ "_created" ] = Date.formatted ( "%d %B %Y", row [ 'created' ].split( " ") [ 0 ]); 
	var _time =  row [ 'send_time' ].split ( ":" );
	row [ "_send_time" ] = _time [ 0 ] + ":" + _time [ 1 ] ;
};
//}}}
//{{{newsletter.admin._info_refresh =  function ( cback )
newsletter.admin._info_refresh =  function ( cback )
{
	newsletter.admin.am_info.show_list ();
	if ( cback ) cback();
};
//}}}
//{{{newsletter.admin.edit_info = function ( id )
newsletter.admin.edit_info = function ( id )
{
        var _post = { action : 'newsletter.ajax.get_info', id_info : id };
        newsletter.ajax ( _post , function ( _resp )
        {
	        newsletter.admin._info_form ( _resp.info );
        });
};
//}}}
//{{{newsletter.admin._info_save =  function ()
newsletter.admin._info_save =  function ()
{
    liwe.utils.notifier.show ( 'Salvato correttamente', 'info', 2000);
};
//}}}
//{{{newsletter.admin.del_info = function ( ids )
newsletter.admin.del_info = function ( ids )
{
		var _title = "Cancellazione Modello";
		var _message = "<u>Elimando il modello saranno eliminate tutte le relazioni <b>continuare</b></u>";
		newsletter.admin._show_message ( _title, _message, function ()
		{
			var _post = { 'action' : 'newsletter.admin.del_info', 'ids' : ids };
			newsletter.admin.ajax ( _post , function ()
			{
				newsletter.admin._info_refresh ( function () 
				{
					liwe.utils.notifier.show ( 'Modello Elimanato correttamente', 'info', 2000)
				});	
			});
		} );
};
//}}}
//{{{newsletter.admin._info_form =  function ( data )
newsletter.admin._info_form =  function ( data )
{
    var dest_div = 'info_form';
    if ( typeof ( data ) == 'undefined' ) data = {};
    var _f = new liwe.form.instance ( 'am_info_form' );
    _f.events [ 'complete' ] = newsletter.admin._info_save;
    _f.hidden ( "action", 'newsletter.admin.set_info' );
    _f.hidden ( 'id_info', data.get ( 'id_info', 0 )  );
    _f.hidden ( 'send_time', data.get ( 'send_time', '' )  );
	_f.email ( { 'label' : 'Mittente', 'name' : 'sender', size : 30, 'maxlength' : 80, 'value' : data.get ( 'sender' , 'info@quotidianoenergia.it' ) , 'mandatory' : true } );
	_f.text ( { 'label' : 'Titolo', 'name' : 'title', size : 30, 'maxlength' : 100, 'value' : data.get ( 'title' , '' ), 'mandatory' : true  } );
	_f.text ( { 'label' : 'Oggetto', 'name' : 'subject', size : 30, 'maxlength' : 100, 'value' : data.get ( 'subject' , '' ), 'mandatory' : true  } );
	_f.label ( { 'label' : 'Ora di invio', value : "<div id='newsletter_info_time_ws'></div>" } );
	_f.jconed ( { 'label' : 'Modello', 'name' : "template", width: 800, height: 500, value : data.get ( 'template' , '' ) } );
    _f.submit ( { value: 'Salva', 'class' : "button green",nonl : true, colspan : 2 } );
    _f.button ( { value: 'Indietro', 'class' : "grey", onclick : "newsletter.admin._info_refresh()"} );
    _f.set ( dest_div );
	newsletter.admin._info_time_render();
    newsletter.admin._show_cnt ( 'info_panel_form', 'info' );

};
//}}}
//{{{newsletter.admin._modify_info_check = function ( el )
newsletter.admin._modify_info_check = function ( el )
{
	var _title = "Cambio tipologia";
	var _message = "<u>Cambiando la tipologia dovrete modificare <b>manualmente</b> le relazioni per gli utenti abbonati e free</u>";
	newsletter.admin._show_message ( _title, _message, null, function ()
	{
		el.checked = ( el.checked ) ? false : true;
	},  [ 450, 5 ] );
	
};
//}}}
//{{{newsletter.admin._info_time_render =  function ()
newsletter.admin._info_time_render =  function ()
{
	var info_form = liwe.form.get ( 'am_info_form' );
	var _send_time = info_form.get_value ( 'send_time' );
	var _time = [ '' , '' ];
	if ( _send_time != "" )
	{
		_time = _send_time.split ( ':' );	
	}

	var _f = new liwe.form.instance ( 'newsletter_info_time' );
	_f.number ( { 'name' : 'ore' , 'size' : 4 , 'maxlength' : 2, 'value' : _time [ 0 ] , 'nonl' : true, 'onchange' : 'newsletter.admin._info_set_time()' } ); 
	_f.number ( { 'name' : 'minuti' , 'size' : 4 , 'maxlength' : 2, 'value' : _time [ 1 ] , 'nonl' : true, 'onchange' : 'newsletter.admin._info_set_time()'  } );
	_f.set ( 'newsletter_info_time_ws' );
	
}
//}}}
//{{{newsletter.admin._info_set_time = function ()
newsletter.admin._info_set_time = function ()
{
	var _time_form =  liwe.form.get ( 'newsletter_info_time' );
	var _ore = _time_form.get_value ( 'ore' );
	var _minuti = _time_form.get_value ( 'minuti' );
	
	var _info_form =  liwe.form.get ( 'am_info_form' );
	_info_form.set_value ( 'send_time' , _ore + ":" + _minuti );		
}
//}}}
//}}}
//{{{SENT
//{{{newsletter.admin._render_sent =  function()
newsletter.admin._render_sent =  function()
{
	var _dct, _admin_title;
	var _admin_title = String.formatDict ( newsletter.templates [ 'ADMIN_TITLE' ], { '_title' : 'GESTIONE SPEDIZIONI' } ); 

	_dct = { '_admin_title' : _admin_title, '_list_title' : 'Elenco spedizioni' , '_form_title' : 'Inserimento/modifica spedizioni'  };

	$(newsletter.admin._dest_div, String.formatDict ( newsletter.templates [ 'ADMIN_SENT_LAYOUT' ], _dct ) );
	newsletter.admin._sent_refresh ();

};
//}}}
//{{{newsletter.admin._am_sent_init = function ( dest_div )
newsletter.admin._am_sent_init = function ( dest_div )
{
        if ( newsletter.admin.am_sent ) return;
        newsletter.admin.am_sent = new AdminManager
                                ( {
                                        'dest_res': dest_div,
                                        'name' : 'am_sent',
                                        'list_action': "newsletter.admin.list_sent",
										'del_action' : "newsletter.admin.del_sent",
                                        'mod_menu_actions': [
                                                                 { func: "newsletter.admin._sent_import_tpl();", 'class' : 'add' , label: 'Aggiungi' }
                    ]
                                } );

        newsletter.admin.am_sent.set_row_fields (
                                [
                                        [ "ID", "id_sent" ],
										[ "Data/Ora di invio", "_sent" ],
										[ "Modello", "title" ],
										[ "Mittente" , "sender" ],
										[ "Oggetto", "subject" ],
                                        [ "Data Inserimento", "_created" ]
                                ]
                                );

        newsletter.admin.am_sent.cbacks [ 'row_manip' ] = newsletter.admin._rwman_sent;
        newsletter.admin.am_sent.cbacks [ 'del_item' ]  = function ( id ) { newsletter.admin.del_sent ( id ); };
        newsletter.admin.am_sent.cbacks [ 'edit_item' ]  = function ( id ) { newsletter.admin.edit_sent ( id ); };
        newsletter.admin.am_sent.cbacks [ 'noresult' ] = function () { newsletter.admin._sent_import_tpl(); };
        newsletter.admin.am_sent.cbacks [ 'show_results' ] = function () { newsletter.admin._show_cnt ( 'sent_panel_list', 'sent' ); };
};
//}}}
//{{{newsletter.admin._rwman_sent = function ( ds, row )
newsletter.admin._rwman_sent = function ( ds, row )
{
	row [ "_id" ] = row [ 'id_sent' ];
	row [ "_created" ] = Date.formatted ( "%d %B %Y", row [ 'created' ].split( " ") [ 0 ]); 
	if ( row [ 'sent' ] == null ) 
	{
		row [ '_sent' ] = "Da inviare alle ore " + row [ 'send_time' ];
	} else {
		row [ '_sent' ] = Date.formatted ( "%d %B %Y alle ore %h:%M", row [ 'sent' ] )
	}

};
//}}}
//{{{newsletter.admin._sent_refresh =  function ( cback )
newsletter.admin._sent_refresh =  function ( cback )
{
	newsletter.admin.am_sent.show_list ();
	newsletter.admin._cache_group_opts ();
	if ( cback ) cback();
};
//}}}
//{{{newsletter.admin._sent_import_tpl 
newsletter.admin._sent_import_tpl = function ()
{

	function _sent_import ()
	{
		var _tpl = _f.get_value ( 'tpl' );
		if ( _tpl == "" ) 
		{
    		liwe.utils.notifier.show ( 'Specificare un modello', 'warn', 2000);
			return;
		};
		var _data =  info [ _tpl ];
		_data [ 'html' ] = _data [ 'template' ];
		newsletter.admin._sent_form  ( _data );

	};


	var _f = new liwe.form.instance ( 'import_info' );
	var _post = { 'action' : 'newsletter.ajax.list_info' };
	var info = {};
	newsletter.ajax ( _post , function ( resp )
	{
		var _opts = [];
		resp.info.iterate ( function ( el )
		{
			info [ el [ 'id_info' ] ] = el;
			_opts.push ( { 'label' : el [ 'title' ], 'value' : el [ 'id_info' ] } );
			
		} );	
		_f.select ( { 'label' : 'Modello', 'name' : 'tpl', 'options' : _opts, force_select : true } );
		_f.button ( { value: 'Importa', 'class' : "blue", onclick : _sent_import, 'nonl' : true } );
		_f.button ( { value: 'Annulla', 'class' : "grey", onclick : "newsletter.admin._sent_refresh()" } );
		_f.set ( 'form_sent_import' );
		newsletter.admin._show_cnt ( 'sent_import' , 'sent' );
	
	} );
};
//}}}
//{{{newsletter.admin.edit_sent = function ( id )
newsletter.admin.edit_sent = function ( id )
{
        var _post = { action : 'newsletter.admin.get_sent', id_sent : id };
        newsletter.ajax ( _post , function ( _resp )
        {
			newsletter.admin._sent_preview ( _resp.sent );
        });
};
//}}}
//{{{newsletter.admin._sent_form =  function ( data )
newsletter.admin._sent_form =  function ( data )
{
    var dest_div = 'sent_form';
    if ( typeof ( data ) == 'undefined' ) data = {};
	var _date =  new Date();
	var _send_time =  data.get ( 'send_time' );
	if ( _send_time )
	{
		var _time =  _send_time.split ( ":" );
		_date.setHours ( _time [ 0 ] );
		_date.setMinutes ( _time [ 1 ] );
		_date.setSeconds ( _time [ 2 ] );
		;
	}
    var f = new liwe.form.instance ( 'am_sent_form' );
    f.hidden ( 'id_sent', data.get ( 'id_sent', 0 ) );
	f.hidden ( 'id_info', data.get ( 'id_info', 0 ) );
	f.hidden ( 'sender', data.get ( 'sender', '' ) );
	f.text ( { 'label' : 'Oggetto', 'name' : 'subject', size : 30, 'maxlength' : 100, 'value' : data.get ( 'subject' , '' ), 'mandatory' : true  } );
	f.hidden ( 'sent', _date.format_date ( "%Y-%m-%d %h:%M:%s" )  );
	var label =  String.formatDict ( newsletter.templates [ 'ADMIN_FRM_LABEL' ] ,{ '_label' :  _date.format_date ( "%d %B %Y alle ore %h:%M" )  } ) ;
	f.label ( { 'label' : 'Data/Ora di invio', 'name' : 'sent', value : label } );
	label =  String.formatDict ( newsletter.templates [ 'ADMIN_FRM_LABEL' ] ,{ '_label' :  data.get ( 'sender', '' ) } );
	f.label ( { 'label' : 'Mittente', value : label } );
	label =  String.formatDict ( newsletter.templates [ 'ADMIN_FRM_LABEL' ] ,{ '_label' :  data.get ( 'subject', '' ) } );
	f.label ( { 'label' : 'Oggetto' , value : label } );
	f.sep ();
	f.jconed ( { 'label' : 'Messaggio', 'name' : "html", width: 800, height: 500, value : data.get ( 'html', '' ) } );
    f.button ( { value: 'Anteprima', 'class' : "button orange",onclick : "newsletter.admin._sent_preview()", nonl : true, colspan : 2 } );
    f.button ( { value: 'Indietro', 'class' : "grey", onclick : "newsletter.admin._sent_refresh()"} );
    f.set ( dest_div );
    newsletter.admin._show_cnt ( 'sent_panel_form', 'sent' );
};
//}}}
//{{{newsletter.admin._sent_preview = function ( data )
newsletter.admin._sent_preview = function ( data )
{
	
	if ( typeof ( data ) == "undefined" )
	{
		var sent_form  = liwe.form.get ( 'am_sent_form' );
		data = sent_form.get_values();
	};
	data [ '_chiudi' ] = newsletter.templates [ 'ADMIN_SENT_CLOSE' ];
	data [ '_invia' ] = '';
	var _title = {  '_title' : 'Invio effettuato' };

	if (  data.get ( 'id_sent', 0 ) == 0 )
	{
		data [ '_invia' ] = newsletter.templates [ 'ADMIN_SENT_INVIA' ];
		_title = {  '_title' : 'Il documento &egrave; pronto per essere inviato' };
	};
	var preview_cnt = String.formatDict ( newsletter.templates [ 'ADMIN_SENT_PREVIEW' ] , data );

	$ ( 'sent_preview_title', String.formatDict ( newsletter.templates [ 'ADMIN_SENT_TITLE' ] , _title ) );
	$ ( 'sent_preview_cnt', preview_cnt );

	var rec_form = new  liwe.form.instance ( "recipients_form" );	
	rec_form.checkbox ( { label: 'Abbonati', name: 'abbonati',  'value' : 1 } );
	rec_form.checkbox ( { label: 'Utenti free', name: 'free',  'value' : 1 } );
	
	rec_form.label ( { value : "Gruppi" } );
	var groups = newsletter.admin._select_opts [ 'group' ];
	for ( i = 0; i < groups.count() ; i++)
	{
		var opt =  groups [ i ];
		var chk_name = "group_" + opt [ 'value' ];
		rec_form.checkbox ( { label: opt [ 'label' ], name: chk_name, 'value' : 1 } );
	};

	rec_form.label ( { value : "Invio test" } );
	rec_form.text ( { 'label' : 'Nome', 'name' : 'name_0', size : 20, 'maxlength' : 30, nonl : true } );
	rec_form.text ( { 'label' : 'Cognome', 'name' : 'lastname_0', size : 20, 'maxlength' : 30, nonl : true } );
	rec_form.email ( { 'label' : 'e-mail', 'name' : 'email_0' , validator : true  } );

	rec_form.text ( { 'label' : 'Nome', 'name' : 'name_1', size : 20, 'maxlength' : 30, nonl : true } );
	rec_form.text ( { 'label' : 'Cognome', 'name' : 'lastname_1', size : 20, 'maxlength' : 30, nonl : true } );
	rec_form.email ( { 'label' : 'e-mail', 'name' : 'email_1' , validator : true } );

	rec_form.text ( { 'label' : 'Nome', 'name' : 'name_2', size : 20, 'maxlength' : 30, nonl : true } );
	rec_form.text ( { 'label' : 'Cognome', 'name' : 'lastname_2', size : 20, 'maxlength' : 30, nonl : true } );
	rec_form.email ( { 'label' : 'e-mail', 'name' : 'email_2' , validator : true } );
	rec_form.set ( "sent_recipients_form" );
	
    newsletter.admin._show_cnt ( 'sent_preview', 'sent' );

};
//}}}
//{{{newsletter.admin.del_sent = function ( ids )
newsletter.admin.del_sent = function ( ids )
{
        var _post = { 'action' : 'newsletter.admin.del_sent', 'ids' : ids };
        newsletter.admin.ajax ( _post , function ()
        {
			newsletter.admin._sent_refresh ( function () 
			{
				liwe.utils.notifier.show ( 'Invio Elimanato correttamente', 'info', 2000)
			});	
        });
};
//}}}
//{{{newsletter.admin._sent_save = function ()
newsletter.admin._sent_save = function ()
{
	var rec_form =  liwe.form.get ( "recipients_form" );
	if ( ! rec_form.check() ) return;

	var _f  = liwe.form.get ( 'am_sent_form' );
	_post = _f.get_values();

	var vals = rec_form.get_values();
	var ok_for_send =  false;
	if ( vals [ 'abbonati' ] ==  1 ) ok_for_send = true;
	if ( vals [ 'free' ] == 1 ) ok_for_send = true;
	
	vals.iterate ( function ( d, k ) 
	{
		if ( k.startsWith ( "group" ) )
		{
			if ( d == 1 ) ok_for_send = true;
		};
		if ( k.startsWith ( "email" ) && d )
		{
			var idx = k.split ( "_" );
			var name = "name_" + idx [ 1 ];
			var lastname = "lastname_" + idx [ 1 ];
			if ( ! vals [ name ] || ! vals [ lastname ] )
			{
				liwe.utils.notifier.show ( "Specificare anche nome e cognome per la mail " + d , 'info', 8000)
				return;
			}else{
				ok_for_send = true;
			}
		}
		_post [ k ] = d;
	} );

	if ( ! ok_for_send ) 
	{
		liwe.utils.notifier.show ( "Specificare una invio valido ", 'info', 8000)
		return;
	}

	_post [ 'action' ] = "newsletter.admin.set_sent";
	
	_code =  $c ( 'div' , 'code',  'sent_html' );
	_code.iterate ( function ( code )
	{
		code.parentNode.removeChild ( code );
	} );

	SiteUtils.clean_html ( $( 'sent_html' ).innerHTML, function ( v )
	{
		_post [ 'html' ] = v [ 'clean_html' ];
		newsletter.admin.ajax ( _post, function ()
		{
				liwe.utils.notifier.show ( 'Invio effettuato correttamente', 'info', 2000)
		}, function ( txt, err_descr, err_code, data )
		{
			if ( ! err_descr ) err_descr = txt;
			newsletter.admin._show_message ( "Attenzione!!", err_descr, null, null, [ 400, 20 ], true )
		}); 
	} );
};
//}}}
//{{{newsletter.admin._sent_close_preview = function ()
newsletter.admin._sent_close_preview = function ()
{
	var _f  = liwe.form.get ( 'am_sent_form' );
	if ( typeof  ( _f ) == "undefined" )
	{
		newsletter.admin._sent_refresh ();
		return;
	};
	newsletter.admin._show_cnt ( 'sent_panel_form', 'sent' );
};
//}}}
//}}}
//{{{GROUP
//{{{newsletter.admin._render_group =  function()
newsletter.admin._render_group =  function()
{
	var _dct, _admin_title;
	var _admin_title = String.formatDict ( newsletter.templates [ 'ADMIN_TITLE' ], { '_title' : 'GESTIONE GRUPPI UTENTI' } ); 

	_dct = { '_admin_title' : _admin_title, '_list_title' : 'Elenco Gruppi' , '_form_title' : 'Inserimento/modifica gruppi'  };

	$(newsletter.admin._dest_div, String.formatDict ( newsletter.templates [ 'ADMIN_GROUP_LAYOUT' ], _dct ) );
	newsletter.admin._group_refresh ();

};
//}}}
//{{{newsletter.admin._am_group_init = function ( dest_div )
newsletter.admin._am_group_init = function ( dest_div )
{
        if ( newsletter.admin.am_group ) return;
        newsletter.admin.am_group = new AdminManager
                                ( {
                                        'dest_res': dest_div,
                                        'name' : 'am_group',
                                        'list_action': "newsletter.ajax.list_group",
                                        'mod_menu_actions': [
                                                                 { func: "newsletter.admin._group_form();", 'class' : 'add' , label: 'Aggiungi' }
                    ]
                                } );

        newsletter.admin.am_group.set_row_fields (
                                [
                                        [ "ID", "id_group" ],
					[ "Titolo" , "title" ],
                                        [ "Data creazione", "_created" ]
                                ]
                                );

        newsletter.admin.am_group.cbacks [ 'row_manip' ] = newsletter.admin._rwman_group;
        newsletter.admin.am_group.cbacks [ 'del_item' ]  = function ( id ) { newsletter.admin.del_group ( id ); };
        newsletter.admin.am_group.cbacks [ 'edit_item' ]  = function ( id ) { newsletter.admin.edit_group ( id ); };
        newsletter.admin.am_group.cbacks [ 'noresult' ] = function () { newsletter.admin._group_form(); };
        newsletter.admin.am_group.cbacks [ 'show_results' ] = function () { newsletter.admin._show_cnt ( 'group_panel_list', 'group' ); };
};
//}}}
//{{{newsletter.admin._rwman_group = function ( ds, row )
newsletter.admin._rwman_group = function ( ds, row )
{
	row [ "_id" ] = row [ 'id_group' ];
	row [ "_created" ] = Date.formatted ( "%d %B %Y", row [ 'created' ].split( " ") [ 0 ]); 
};
//}}}
//{{{newsletter.admin._group_refresh =  function ( cback )
newsletter.admin._group_refresh =  function ( cback )
{
	newsletter.admin.am_group.show_list ();
	if ( cback ) cback();
};
//}}}
//{{{newsletter.admin.edit_group = function ( id )
newsletter.admin.edit_group = function ( id )
{
        var _post = { action : 'newsletter.ajax.get_group', id_group : id };
        newsletter.ajax ( _post , function ( _resp )
        {
	        newsletter.admin._group_form ( _resp.group );
        });
};
//}}}
//{{{newsletter.admin._group_save =  function ()
newsletter.admin._group_save =  function ()
{
    liwe.utils.notifier.show ( 'Salvato correttamente', 'info', 2000);
};
//}}}
//{{{newsletter.admin.del_group = function ( ids )
newsletter.admin.del_group = function ( ids )
{
		var _title = "Cancellazione Gruppo";
		var _message = "<u>Elimando il gruppo gli utenti ad esso associati verranno impostati sul gruppo free <b>continuare</b></u>";
		newsletter.admin._show_message ( _title, _message, function ()
		{
			var _post = { 'action' : 'newsletter.admin.del_group', 'ids' : ids };
			newsletter.admin.ajax ( _post , function ()
			{
				newsletter.admin._group_refresh ( function () 
				{
					liwe.utils.notifier.show ( 'Gruppo Elimanato correttamente', 'info', 2000)
				});	
			});
		} );
};
//}}}
//{{{newsletter.admin._group_form =  function ( data )
newsletter.admin._group_form =  function ( data )
{
    var dest_div = 'group_form';
    if ( typeof ( data ) == 'undefined' ) data = {};
    var _f = new liwe.form.instance ( 'am_group_form' );
    _f.events [ 'complete' ] = newsletter.admin._group_save;
    _f.hidden ( "action", 'newsletter.admin.set_group' );
    _f.hidden ( 'id_group', data.get ( 'id_group', 0 )  );
	_f.text ( { 'label' : 'Titolo', 'name' : 'title', size : 30, 'maxlength' : 30, 'value' : data.get ( 'title' , '' ), 'mandatory' : true  } );
    _f.submit ( { value: 'Salva', 'class' : "button green",nonl : true, colspan : 2 } );
    _f.button ( { value: 'Indietro', 'class' : "grey", onclick : "newsletter.admin._group_refresh()"} );
    _f.set ( dest_div );
    newsletter.admin._show_cnt ( 'group_panel_form', 'group' );

};
//}}}
//}}}
//{{{newsletter.admin.init = function ( dest_div )
newsletter.admin.init = function ( dest_div )
{
	if ( ! newsletter.templates )
	{
		newsletter.load_templates ( function () { newsletter.admin._init ( dest_div); } );
		return;
	}   
	newsletter.admin._init ( dest_div );
};  
//}}}

//{{{REMOVED FUNCTIONS
/*
//{{{newsletter.admin._reload_extra = function ()
newsletter.admin._reload_extra = function ()
{
	
	var _f = liwe.form.get ( 'am_subscriber_form' );
	var id_subscriber =  _f.get_value ( 'id_subscriber' );
	if ( id_subscriber == 0 ) return;
	newsletter.admin._subscriber_extra( id_subscriber, _f.get_value ( 'uid' ) );
	
}
//}}}
//{{{newsletter.admin._subscriber_extra  ( id_subscriber )
newsletter.admin._subscriber_extra = function ( id_subscriber, uid )
{
	if ( id_subscriber == 0 ) return;
	var pan_groups = { 'on' : [] , 'off' : []};
    var attrs = {
            head_left: 'Disattivate',
            head_right: 'Attivate'
            };
    var gr = '';
    var pan = new WWL.panels ( 'subscriber_relations', attrs );

    function _render ()
    {
        pan.set_cbacks ( 'done', newsletter.admin._rel_save );
        pan.render ( 'relations' );
        pan.populate ( pan_groups [ 'off' ] , pan_groups [ 'on'] );

		var _el = $e ( 'subscriber_relations' );
		_el.style.display = "block";
		liwe.fx.fade_in ( _el );
    };

    function _req_data ()
    {
        newsletter.ajax ( _post, function ( data )
		{
			data.check.iterate ( function ( _item )
			{
				if ( _item [ 'free' ] == 0 && uid == 0 ) return;	
				gr =  'on';
				if ( _item [ 'id_subscriber' ] == 0 ) gr = 'off';
				pan_groups [ gr ].push ( { id : _item [ 'id_info' ], name : _item [ 'title' ], title : _item [ 'title' ] } );
			});
           	_render(); 
         });
    };

    var _post = {
            'action' : 'newsletter.ajax.check_rel',
            'id_subscriber' : id_subscriber
            };
	_req_data ();
			
};
//}}}
//{{{RELATIONS
//{{{newsletter.admin._render_relations =  function()
newsletter.admin._render_relation =  function()
{
	var _dct, _admin_title;
	var _admin_title = String.formatDict ( newsletter.templates [ 'ADMIN_TITLE' ], { '_title' : 'GESTIONE RELAZIONI' } ); 

	$(newsletter.admin._dest_div, String.formatDict ( newsletter.templates [ 'ADMIN_RELATION_LAYOUT' ], { '_admin_title' : _admin_title } ) );
	newsletter.admin._relation_form();

};
//}}}
//{{{newsletter.admin._relation_refresh = function( id_info )
newsletter.admin._relation_refresh = function( id_info )
{
	var _tools = $el ( "relation_update");
	_tools.style.display = 'block' ;
    var attrs = {
            head_left: 'Disattivati',
            head_right: 'Attivi',
			templates : { 'panels-manage-group' : newsletter.templates [ 'ADMIN_PANELS' ] }
            };
    newsletter.admin._pan_reg= new WWL.panels ( 'relation_reg', attrs );
    newsletter.admin._pan_free= new WWL.panels ( 'relation_free', attrs );

	var gr_reg = { 'on' : [] , 'off' : [] };
	var gr_free = { 'on' : [] , 'off' : [] };
	var groups = {};
	var gr = '';

    function _render ()
    {
        newsletter.admin._pan_reg.render ( 'relation_reg' );
        newsletter.admin._pan_free.render ( 'relation_free' );

        newsletter.admin._pan_reg.populate ( gr_reg [ 'off' ] , gr_reg [ 'on'] );
        newsletter.admin._pan_free.populate ( gr_free [ 'off' ] , gr_free [ 'on'] );
    };


    function _req_data ()
    {
        newsletter.admin.ajax ( _post, function ( data )
		{
			var check =  data.check;
			data.check.iterate ( function ( _item )
			{
				if ( _item [ 'free' ] == 0 && _item [ 'uid' ] == 0 ) return;
				gr = 'on';
				groups = gr_reg
				if ( _item [ 'uid' ] == 0 ) groups = gr_free;
				if ( _item [ 'id_info' ] == 0 ) gr = 'off';
				var _title = _item [ 'nome' ] + ' ' + _item [ 'cognome' ];
				groups [ gr ].push ( { id : _item [ 'id_subscriber' ], name : _item [ 'email' ], title : _title } );
			} );
           	_render(); 
         });
    };

    var _post = {
            'action' : 'newsletter.admin.check_info_rel',
            'id_info' : id_info
            };
	_req_data ();
};
//}}}
//{{{newsletter.admin._rel_info_save = function ()
newsletter.admin._rel_info_save = function ()
{
	var gr_free = newsletter.admin._pan_free.return_group() [ 'group_right' ];
	var gr_reg = newsletter.admin._pan_reg.return_group() [ 'group_right' ];
	var _subscriber = [];
	if ( gr_free ) _subscriber =  gr_free.split ( "|" );
	if ( gr_reg ) _subscriber = _subscriber.concat ( gr_reg.split ( "|" ) );

	var _f = liwe.form.get ( 'model_select' );
	_id =  _f.get_value ( 'id_info' );
	var _post  = { 
					'action' : 'newsletter.admin.set_info_rel' ,
					'id_info' : _id,
					'rels' : _subscriber.join ( "|" ) 
				}
	
    newsletter.admin.ajax ( _post, function ( data ) 
	{
    	liwe.utils.notifier.show ( 'Aggionamento Relazioni', 'info', 2000);
	} );
};
//}}}
//{{{newsletter.admin._relation_form = function ()
newsletter.admin._relation_form = function ()
{
	function _select_model ()
	{
		var _id_info = _f.get_value ( 'id_info' );
		if ( _id_info == "" ) 
		{

			var _tools = $el ( "relation_update");
			_tools.style.display = 'none';
			$ ( 'relation_reg' , '' );
			$ ( 'relation_free' , '' );
    		liwe.utils.notifier.show ( 'Specificare un modello', 'warn', 2000);
			return;
		};
		newsletter.admin._relation_refresh ( _id_info);
	};

	var _f = new liwe.form.instance ( 'model_select' );
	var _post = { 'action' : 'newsletter.ajax.list_info' };
	var info = {};
	newsletter.ajax ( _post , function ( resp )
	{
		var _opts = [];
		resp.info.iterate ( function ( el )
		{
			info [ el [ 'id_info' ] ] = el;
			_opts.push ( { 'label' : el [ 'title' ], 'value' : el [ 'id_info' ] } );
			
		} );	
		_f.select ( { 'label' : 'Seleziona un modello', 'name' : 'id_info', 'options' : _opts, force_select : true } );
		_f.set ( 'relation_frm' );
		var _select = _f.get_element ( 'id_info' );
		_select.onchange = _select_model;
	
	} );
}
//}}}
//{{{newsletter.admin._rel_save = function ( group_list )
newsletter.admin._rel_save = function ( group_list )
{
	var _f = liwe.form.get ( 'am_subscriber_form' );
	_id =  _f.get_value ( 'id_subscriber' );
	var _post  = { 
					'action' : 'newsletter.ajax.set_subscriber_rel' ,
					'id_subscriber' : _id,
					'rels' : group_list [ 'group_right' ] 
				}
	
    newsletter.admin.ajax ( _post, function ( data ) {} );
	
}
//}}}
//}}}
*/
//}}}
